package recallin.activities;

import java.util.ArrayList;

import oauth.signpost.OAuth;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 
 * @author philipmasek
 * Handles logout for the user.
 */

public class SettingsActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ListView listView = new ListView(this);
		ArrayList<String> list = new ArrayList<String>();
		list.add("Logout");

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				getApplicationContext(), android.R.layout.simple_list_item_1,
				list);
		listView.setAdapter(adapter);

		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				switch (arg2) {
				case 0:
					getSharedPreferences(LoginActivity.PREFS_NAME, MODE_PRIVATE)
							.edit()
							.putString(LoginActivity.PREF_PASSWORD, null)
							.putString(LoginActivity.PREF_PASSWORD, null)
							.commit();
					Intent intent = new Intent(SettingsActivity.this,
							LoginActivity.class);
					Toast.makeText(SettingsActivity.this, "Logged out!",
							Toast.LENGTH_LONG).show();
					startActivity(intent);
					break;

				default:
					break;
				}
			}
		});

		setContentView(listView);
	}

	private void clearCredentials() {
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		final Editor edit = prefs.edit();
		edit.remove(OAuth.OAUTH_TOKEN);
		edit.remove(OAuth.OAUTH_TOKEN_SECRET);
		edit.commit();
	}
	
	
}
